﻿@model PcaParqueos.BOL.oVwRegistro 

@{
    var X = Html.X();
}

@(
 X.GridPanel()
        .ID("GridRegistrosActivos")
        .Title("Mis registros activos")
        .Flex(1)
        .Store(
            X.StoreForModel()
                .ID("storeRegistrosActivos")
                .Parameters(p =>
                {
                    p.Add(new StoreParameter() { Name = "placa", Value = "App.placaVehiculo.getValue()", Mode = ParameterMode.Raw });
                })
                .Proxy(
                    X.AjaxProxy()
                        .Url(Url.Action("GetListActivos", "RegistroActivo"))
                        .Reader(X.JsonReader().RootProperty("data"))
                )
                .RemoteSort(false)
        )
        .ColumnModel(
                X.Column().DataIndex(Model, m => m.tipo_vehiculo).Text("Tipo vehiculo").Width(120),
                X.Column().DataIndex(Model, m => m.placa).Text("Placa").Width(120),
                X.CheckColumn().DataIndex(Model, m => m.es_abonado).Text("Abonado").Width(120),
                X.DateColumn().DataIndex(Model, m => m.fecha_hora_ingreso).Text("Fecha-Hora ingreso").Format("dd-MM-yyyy hh:mm tt").Align(Alignment.Center).Flex(1),
                X.Column().DataIndex(Model, m => m.tiempo).Text("Tiempo transcurrido").Align(Alignment.Center).Flex(1),
                X.CommandColumn().Hideable(false).Text("Operaciones").Align(Alignment.Center)
                    .Commands(
                        X.GridCommand().CommandName("cmdEmitirComprobante").ToolTip(t => t.Text = "Emitir comprobante").Icon(Icon.ApplicationForm)
                    )
                    .DirectEvents(de =>
                    {
                        de.Command.Url = Url.Action("RunCommandGrid", "RegistroActivo");
                        de.Command.ExtraParams.Add(new Parameter { Name = "commandName", Value = "command", Mode = ParameterMode.Raw });
                        de.Command.ExtraParams.Add(new Parameter { Name = "registroId", Value = "record.data.registro_id", Mode = ParameterMode.Raw });
                        de.Command.Before = "Ext.getBody().mask('Cargando...!', 'x-mask-loading');";
                        de.Command.Complete = "Ext.getBody().unmask();";
                        de.Command.Failure = "PcaGlobal.showError(result.msg);";
                    })
        )
        .TopBar(
            X.Toolbar()
                .Items(
                    X.Button()
                        .ID("btnRegistrar")
                        .Text("Registrar Ingreso")
                        .Icon(Icon.Add)
                        .DirectEvents(de =>
                        {
                            de.Click.Url = Url.Action("FrmRegistrar", "RegistroActivo");
                            de.Click.Before = "Ext.getBody().mask('Cargando...!', 'x-mask-loading');";
                            de.Click.Failure = @"PcaGlobal.showError(result.msg);
                                                 App.storeLiquidacionesActivas.reload();
                                                 App.btnRegistrar.setDisabled(true);
                                                 App.placaVehiculo.setDisabled(true);
                                                 App.btnActualizarGrid.setDisabled(true);";
                            de.Click.Complete = "Ext.getBody().unmask();";
                        }),
                    X.ToolbarFill(),
                    X.TextField()
                        .ID("placaVehiculo")
                        .Width(150)
                        .EnableKeyEvents(true)
                        .EmptyText("Ingrese Placa...")
                        .Cls("upperTxt") 
                        .Triggers(
                            X.FieldTrigger()
                                .Hidden(true)
                                .Icon(TriggerIcon.Clear)
                        )
                        .Listeners(l =>
                        {
                            l.KeyUp.Handler = @"if (Ext.isEmpty(App.placaVehiculo.getValue(), false)) {
                                                    App.placaVehiculo.setValue('');
                                                    App.placaVehiculo.getTrigger(0).hide();
                                                } else {
                                                    App.placaVehiculo.getTrigger(0).show();
                                                }";
                            l.TriggerClick.Handler = @"App.placaVehiculo.setValue('');
                                                       App.placaVehiculo.getTrigger(0).hide();
                                                       App.GridRegistrosActivos.getSelectionModel().deselectAll(); 
                                                       App.storeRegistrosActivos.load();";
                            l.SpecialKey.Handler = @"if(e.getKey() == e.ENTER){
                                                        e.stopEvent();
                                                        App.GridRegistrosActivos.getSelectionModel().deselectAll(); 
                                                        App.storeRegistrosActivos.load();
                                                    }";
                        }),
                    X.Button()
                        .ID("btnActualizarGrid")
                        .Text("Actualizar")
                        .Icon(Icon.ArrowRotateAnticlockwise)
                        .Handler("App.GridRegistrosActivos.getSelectionModel().deselectAll(); App.storeRegistrosActivos.load();")
                )
        )
)
